package com.shop2cn.iapi.shenqisettlement.testcase;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.common.lang.CipherUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.shenqi.ShenqiSettlementService;
import com.ymttest.database.model.shenqisettlement.OrderSettlementDetail;
import com.ymttest.database.model.shenqisettlement.UserAccountDetail;
import com.ymttest.database.model.shenqisettlement.Withdraw;
import com.ymttest.database.mongo.OrderQueryWapper;
import com.ymttest.database.sqlwapper.shenqisettlement.OrderSettlementDetailWrapper;
import com.ymttest.database.sqlwapper.shenqisettlement.SqTaskWrapper;
import com.ymttest.database.sqlwapper.shenqisettlement.UserAccountDetailWrapper;
import com.ymttest.database.sqlwapper.shenqisettlement.WithdrawWrapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

@Ignore
public class Ts_GenerateAccountDataPerDay {

	private static WithdrawWrapper wrapper = new WithdrawWrapper();
	private static UserAccountDetailWrapper userAcccountDetailWrapper = new UserAccountDetailWrapper();
	private static SqTaskWrapper sqTaskWrapper = new SqTaskWrapper();
	private static OrderSettlementDetailWrapper orderSettlementDetailWrapper = new OrderSettlementDetailWrapper();
	private static OrderQueryWapper orderQueryWapper = new OrderQueryWapper();

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("生成每日账单数据");
	}

	@Before
	public void caseUp() {
		
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult("api/GenerateAccountDataPerDay");
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	private void updateSqTaskIfExist(String taskType) {
		
		Date taskTime = YMTDateUtil.getDate(
				YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMD);
		
		if (sqTaskWrapper.selectByTaskTimeAndTaskType(taskTime, taskType).getTask_status() == 1)
			sqTaskWrapper.updateByTaskTimeAndTaskTypeSelective(taskTime, taskType);
	}
	
	public void verify(Object object, int receiptType) {
		
		UserAccountDetail expecDetail = new UserAccountDetail();
		if (receiptType == 1) {
			
			Long userId = ((OrderSettlementDetail) object).getUser_id();
			Long orderId = ((OrderSettlementDetail) object).getOrder_id();
			
			OrderSettlementDetail detailPo = orderSettlementDetailWrapper
					.selectByOrderIdAndUserId(orderId, userId);
			
			List<UserAccountDetail> userAccountDetailList = userAcccountDetailWrapper
					.selectByUserIdAndBizId(userId, orderId.toString());
			
			int size = 2;
			
			Logger.comment(String.format("开始验证userId:%s, bizId:%s", userId, orderId));
			
			expecDetail.setUser_id(userId);
			expecDetail.setReceipt_type((byte)1);
			expecDetail.setBiz_id(orderId.toString());
			expecDetail.setCurrency(detailPo.getSettlement_currency());
			expecDetail.setBiz_time(orderQueryWapper.findById(6275048699L).getPaidTime());
			expecDetail.setRecorded_time(detailPo.getOrder_create_time());
			
			UserAccountDetail actualDetail1 = userAccountDetailList
					.stream()
					.filter(userAccountDetail -> userAccountDetail
							.getAccount_fee_type() == 1)
					.collect(Collectors.toList()).get(0);
			
			expecDetail.setAccount_fee_type((byte)1);
			
			if (detailPo.getSettlement_currency().equalsIgnoreCase("CNY"))
				expecDetail.setAmount(detailPo.getSettlement_amount());
			else
				expecDetail.setAmount(detailPo.getTotal_foreign_amount());
			
			this.verifyObject(expecDetail, actualDetail1);
			
			UserAccountDetail actualDetail2 = userAccountDetailList
					.stream()
					.filter(userAccountDetail -> userAccountDetail
							.getAccount_fee_type() == 2)
					.collect(Collectors.toList()).get(0);
			
			expecDetail.setAccount_fee_type((byte)2);
			expecDetail.setAmount(detailPo.getPlatform_fee().negate());
			
			this.verifyObject(expecDetail, actualDetail2);
			
			if (detailPo.getIs_rollback() && detailPo.getSettlement_status() == 2) {
				
				UserAccountDetail actualDetail6 = userAccountDetailList
						.stream()
						.filter(userAccountDetail -> userAccountDetail
								.getAccount_fee_type() == 6)
						.collect(Collectors.toList()).get(0);
				
				expecDetail.setAccount_fee_type((byte)6);
				expecDetail.setBiz_time(detailPo.getUpdate_time());

				expecDetail.setAmount(detailPo.getSettlement_amount().negate());
				
				this.verifyObject(expecDetail, actualDetail6);
				
				UserAccountDetail actualDetail7 = userAccountDetailList
						.stream()
						.filter(userAccountDetail -> userAccountDetail
								.getAccount_fee_type() == 7)
						.collect(Collectors.toList()).get(0);
				
				expecDetail.setAccount_fee_type((byte)7);
				expecDetail.setAmount(detailPo.getPlatform_fee());
				
				this.verifyObject(expecDetail, actualDetail7);
				
				size += 2;
			}
			
			Logger.verifyEquals(userAccountDetailList.size(), size, "验证userAccountDetailList.size");
			
		} else if (receiptType == 2) {
			
			Withdraw withdrawPo = wrapper.selectByPrimaryKey(((Withdraw) object).getWithdraw_id());
			List<UserAccountDetail> userAccountDetailList = userAcccountDetailWrapper
					.selectByBizId(withdrawPo.getWithdraw_id());
			
			int size = 2;
			
			Logger.comment("开始验证：" + withdrawPo.getWithdraw_id());
			
			expecDetail.setUser_id(withdrawPo.getUser_id());
			expecDetail.setReceipt_type((byte)2);
			expecDetail.setBiz_id(withdrawPo.getWithdraw_id());
			expecDetail.setCurrency(withdrawPo.getApply_withdraw_currency());
			expecDetail.setBiz_time(withdrawPo.getAdd_time());
			expecDetail.setRecorded_time(withdrawPo.getUpdate_time());
			
			UserAccountDetail actualDetail3 = userAccountDetailList
					.stream()
					.filter(userAccountDetail -> userAccountDetail
							.getAccount_fee_type() == 3)
					.collect(Collectors.toList()).get(0);
			
			expecDetail.setAccount_fee_type((byte)3);
			expecDetail.setAmount(withdrawPo.getReal_withdraw_amount().negate());
			
			this.verifyObject(expecDetail, actualDetail3);
			
			UserAccountDetail actualDetail4 = userAccountDetailList
					.stream()
					.filter(userAccountDetail -> userAccountDetail
							.getAccount_fee_type() == 4)
					.collect(Collectors.toList()).get(0);
			
			expecDetail.setAccount_fee_type((byte)4);
			expecDetail.setAmount(withdrawPo.getWithdraw_fee_amount().negate());
			
			this.verifyObject(expecDetail, actualDetail4);

			if (withdrawPo.getAccount_status() == 2) {
				
				size = size + 2;
				
				UserAccountDetail actualDetail8 = userAccountDetailList
						.stream()
						.filter(userAccountDetail -> userAccountDetail
								.getAccount_fee_type() == 8)
						.collect(Collectors.toList()).get(0);
				
				expecDetail.setAccount_fee_type((byte)8);
				expecDetail.setAmount(withdrawPo.getReal_withdraw_amount());
				
				this.verifyObject(expecDetail, actualDetail8);
				
				UserAccountDetail actualDetail9 = userAccountDetailList
						.stream()
						.filter(userAccountDetail -> userAccountDetail
								.getAccount_fee_type() == 9)
						.collect(Collectors.toList()).get(0);
				
				expecDetail.setAccount_fee_type((byte)9);
				expecDetail.setAmount(withdrawPo.getWithdraw_fee_amount());
				
				this.verifyObject(expecDetail, actualDetail9);
			}
			
			if (null != withdrawPo.getExchange_fee_amount()) {
				
				UserAccountDetail actualDetail5 = userAccountDetailList
						.stream()
						.filter(userAccountDetail -> userAccountDetail
								.getAccount_fee_type() == 5)
						.collect(Collectors.toList()).get(0);
				
				expecDetail.setAccount_fee_type((byte)5);
				expecDetail.setAmount(withdrawPo.getExchange_fee_amount().negate());
				
				this.verifyObject(expecDetail, actualDetail5);
				
				size = size + 1;
			}
			
			Logger.verifyEquals(userAccountDetailList.size(), size, "验证userAccountDetailList.size");
		}
	}
	
	public void verifyObject(UserAccountDetail expected, UserAccountDetail actual) {
		
		Logger.comment("开始验证" + actual.getAccount_fee_type());
		
		Logger.verifyEquals(expected.getUser_id(), actual.getUser_id(), "验证User_id");
		Logger.verifyEquals(expected.getReceipt_type(), actual.getReceipt_type(), "验证Receipt_type");
		Logger.verifyEquals(expected.getAccount_fee_type(), actual.getAccount_fee_type(), "验证Account_fee_type");
		Logger.verifyEquals(expected.getBiz_id(), actual.getBiz_id(), "验证Biz_id");
		Logger.verifyEquals(expected.getCurrency(), actual.getCurrency(), "验证Currency");
		Logger.verifyEquals(expected.getAmount(), actual.getAmount(), "验证Amount");
		Logger.verifyEquals(expected.getBiz_time(), actual.getBiz_time(), "验证Biz_time");
		Logger.verifyEquals(expected.getRecorded_time(), actual.getRecorded_time(), "验证Recorded_time");
	}
	
	public String encryptAES(String bankAccountNumber) {
		
		String secret = null;
		
		try {
			secret = CipherUtil.encryptAES("123456", bankAccountNumber);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return secret;
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_001() {
		Logger.start(true, "验证提现成功账单详情，Account_status为1");
		try {
			
	    	Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(1);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(null);
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_002() {
		Logger.start(true, "验证提现汇兑成功账单详情，Account_status为1且Exchange_fee_amount不为null");
		try {
			
			Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(1);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(new BigDecimal("3.00"));
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_003() {
		Logger.start(true, "验证提现失败账单详情,Account_status为2");
		try {
			
			Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(2);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(null);
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_004() {
		Logger.start(true, "验证提现汇兑失败账单详情，Account_status为2且Exchange_fee_amount不为null");
		try {
			
			Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(2);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(new BigDecimal("3.00"));
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_005() {
		Logger.start(true, "验证提现成功账单详情(账户返款异常 )，Account_status为4");
		try {
			
	    	Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(4);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(null);
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_006() {
		Logger.start(true, "验证提现汇兑成功账单详情(账户返款异常 )，Account_status为4且Exchange_fee_amount不为null");
		try {
			
			Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(4);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(new BigDecimal("3.00"));
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	withdrawPo.setWithdraw_type(0);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(withdrawPo, 2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_007() {
		Logger.start(true, "验证订单结算成功账单详情，有结算时间且rollback为false");
		try {
			
			OrderSettlementDetail detail = new OrderSettlementDetail();
			
	    	detail.setOrder_id(6275048699L);
	    	detail.setUser_id((long)TestDataManager.getRandomIntNum(7));
	    	detail.setTotal_rmb_amount(BigDecimal.TEN);
	    	detail.setTotal_foreign_amount(BigDecimal.ONE);
	    	detail.setForeign_currency("USD");
	    	detail.setExchange_rate("1.169590643274853801169590643");
	    	detail.setPlatform_fee_rate(BigDecimal.ZERO);
	    	detail.setPlatform_fee(new BigDecimal("2.00"));
	    	detail.setSettlement_currency("USD");
	    	detail.setSettlement_amount(new BigDecimal("9.00"));
	    	detail.setSettlement_status(1);
	    	detail.setSettlement_time(YMTDateUtil.getDate());
	    	detail.setIs_rollback(false);
	    	detail.setIs_proxy_product(true);
	    	detail.setGoods_owner_id(2490L);
	    	detail.setParent_proxy_id(null);
	    	detail.setUser_role("GOODS_OWNER");
	    	detail.setOrder_create_time(YMTDateUtil.getDate());
	    	detail.setRemark("autotest");
	    	detail.setIs_personal_applet(false);
	    	detail.setAdd_time(YMTDateUtil.getDate());
	    	detail.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	
	    	orderSettlementDetailWrapper.insert(detail);
	    	
	    	this.updateSqTaskIfExist("SETTLEMENT");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(detail, 1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_008() {
		Logger.start(true, "验证订单结算成功账单详情，结算币种为CNH，有结算时间且rollback为false");
		try {
			
			OrderSettlementDetail detail = new OrderSettlementDetail();
			
	    	detail.setOrder_id(6275048699L);
	    	detail.setUser_id((long)TestDataManager.getRandomIntNum(7));
	    	detail.setTotal_rmb_amount(BigDecimal.TEN);
	    	detail.setTotal_foreign_amount(BigDecimal.ONE);
	    	detail.setForeign_currency("CNH");
	    	detail.setExchange_rate("1.169590643274853801169590643");
	    	detail.setPlatform_fee_rate(BigDecimal.ZERO);
	    	detail.setPlatform_fee(new BigDecimal("2.00"));
	    	detail.setSettlement_currency("CNH");
	    	detail.setSettlement_amount(new BigDecimal("9.00"));
	    	detail.setSettlement_status(1);
	    	detail.setSettlement_time(YMTDateUtil.getDate());
	    	detail.setIs_rollback(false);
	    	detail.setIs_proxy_product(true);
	    	detail.setGoods_owner_id(2490L);
	    	detail.setParent_proxy_id(null);
	    	detail.setUser_role("GOODS_OWNER");
	    	detail.setOrder_create_time(YMTDateUtil.getDate());
	    	detail.setRemark("autotest");
	    	detail.setIs_personal_applet(false);
	    	detail.setAdd_time(YMTDateUtil.getDate());
	    	detail.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	
	    	orderSettlementDetailWrapper.insert(detail);
	    	
	    	this.updateSqTaskIfExist("SETTLEMENT");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(detail, 1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_009() {
		Logger.start(true, "验证订单结算成功账单详情，有结算时间且rollback为true");
		try {
			
			OrderSettlementDetail detail = new OrderSettlementDetail();
			
	    	detail.setOrder_id(6275048699L);
	    	detail.setUser_id((long)TestDataManager.getRandomIntNum(7));
	    	detail.setTotal_rmb_amount(BigDecimal.TEN);
	    	detail.setTotal_foreign_amount(BigDecimal.ONE);
	    	detail.setForeign_currency("USD");
	    	detail.setExchange_rate("1.169590643274853801169590643");
	    	detail.setPlatform_fee_rate(BigDecimal.ZERO);
	    	detail.setPlatform_fee(new BigDecimal("2.00"));
	    	detail.setSettlement_currency("USD");
	    	detail.setSettlement_amount(new BigDecimal("9.00"));
	    	detail.setSettlement_status(2);
	    	detail.setSettlement_time(YMTDateUtil.getDate());
	    	detail.setIs_rollback(true);
	    	detail.setIs_proxy_product(true);
	    	detail.setGoods_owner_id(2490L);
	    	detail.setParent_proxy_id(null);
	    	detail.setUser_role("GOODS_OWNER");
	    	detail.setOrder_create_time(YMTDateUtil.getDate());
	    	detail.setRemark("autotest");
	    	detail.setIs_personal_applet(false);
	    	detail.setAdd_time(YMTDateUtil.getDate());
	    	detail.setUpdate_time(YMTDateUtil.getDate(YMTDateUtil.getBeforeOrNextDay(-1), YMTDateUtil.YMDHMS));
	    	
	    	orderSettlementDetailWrapper.insert(detail);
	    	
	    	this.updateSqTaskIfExist("SETTLEMENT");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);

			verify(detail, 1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GenerateAccountDataPerDay_010() {
		Logger.start(true, "验证updateTime为今天，无法生成账单详情");
		try {
			
	    	Withdraw withdrawPo = new Withdraw();
	    	
	    	withdrawPo.setWithdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setUser_id(500078247L);
	    	withdrawPo.setBank_account_number(encryptAES("autotest_bank_account_number"));
	    	withdrawPo.setBank_account_currency("autotest_bank_account_currency");
	    	withdrawPo.setBank_account_name("autotest_bank_account_name");
	    	withdrawPo.setBank_name("autotest_bank_name");
	    	withdrawPo.setWithdraw_status(1);
	    	withdrawPo.setAccount_status(1);
	    	withdrawPo.setCountry("USA");
	    	withdrawPo.setBatch_withdraw_id("autotest" + TestDataManager.randomStr(20));
	    	withdrawPo.setReal_withdraw_amount(BigDecimal.ONE);
	    	withdrawPo.setApply_withdraw_amount(BigDecimal.TEN);
	    	withdrawPo.setWithdraw_fee_amount(new BigDecimal("2.00"));
	    	withdrawPo.setTe_receive_amount(new BigDecimal("0.05"));
	    	withdrawPo.setTe_receive_currency("USD");
	    	withdrawPo.setWithdraw_fee_amount_usd(new BigDecimal("5.00"));
	    	withdrawPo.setTe_rate(new BigDecimal("1.20"));
	    	withdrawPo.setRemark(null);
	    	withdrawPo.setAdd_time(YMTDateUtil.getDate());
	    	withdrawPo.setUpdate_time(YMTDateUtil.getDate());
	    	withdrawPo.setAccount_type(1);
	    	withdrawPo.setExchange_fee_rate(BigDecimal.ONE);
	    	withdrawPo.setExchange_fee_amount(null);
	    	withdrawPo.setApply_withdraw_currency("USD");
	    	withdrawPo.setAccount_deduct_time(null);
	    	withdrawPo.setAccount_refund_time(null);
	    	
	    	wrapper.insert(withdrawPo);
	    	
	    	this.updateSqTaskIfExist("WITHDRAW");

	    	ShenqiSettlementService.generateAccountDataPerDay();
			Thread.sleep(2000);
			
			List<UserAccountDetail> userAccountDetailList = userAcccountDetailWrapper
					.selectByBizId(withdrawPo.getWithdraw_id());

			Logger.verifyEquals(0, userAccountDetailList.size(), "验证userAccountDetailList的size");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	public static void main(String[] args) throws Exception {
		Logger.comment(CipherUtil.encryptAES("123456", "autotest_bank_account_number"));
	}
}
